package zdy.web.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
//import javax.servlet.annotation.WebFilter;

/**
 * Servlet Filter implementation class MyFilter
 */
//@WebFilter(filterName="/CodeFilter",urlPatterns="/*",initParams={@WebInitParam(name ="EXCLUDED_PAGES" , value = "login.jsp;loginAction")})
//@WebFilter("/*")
public class MyFilter implements Filter {
	 private int hitCount; 
    /**
     * Default constructor. 
     */
    public MyFilter() {
        // TODO Auto-generated constructor stub
        hitCount = 0;
    }
	/**
	 * @see Filter#destroy()
	 */
	public void destroy() {
		// TODO Auto-generated method stub
	}
	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		// TODO Auto-generated method stub
		// place your code here
		// 输出站点名称
		System.out.println("站点网址：http://www.zdy.cn");
	    hitCount++;
	    request.setAttribute("hitCount", hitCount);
		// 把请求传回过滤链	
		// pass the request along the filter chain
		chain.doFilter(request, response);
	}

	/**
	 * @see Filter#init(FilterConfig)
	 */
	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
		// 从web.xml 文件中提取 filter/init-param/param-name=Site 的 value
		String site = fConfig.getInitParameter("Site"); 
	
		// 输出初始化参数 调试用
		System.out.println("Site.value: " + site); 
	}

}
